import { executeSql } from '../until/db.js';


//15.获取统计数据
export const selectDataInfo = function () {
    let sql = `select 
  count(distinct a.id) as totalArticles,  
  count(c.articleId) as totalComments     
from articles a 
left join comments c on a.id = c.articleId;`;
    return executeSql(sql)
}

//16.日新增文章数量统计
export const selectDataArticles = function () {
    let sql = `SELECT 
    DATE(date) AS publish_date,  
    COUNT(id) AS article_count        
    FROM 
    articles 
    GROUP BY 
    DATE(date)  
    ORDER BY 
    publish_date DESC; `;
    return executeSql(sql)
}


//17.各类型文章数量统计
export const selectDataCategory = function () {
    let sql = `select 
    c.name article_type,  
    COUNT(a.id) article_count        
    from 
  articles a  
    JOIN 
  categories c  
    ON 
  a.categoryId = c.id  
    group by 
  c.name  
    order by 
  c.id DESC;`;
    return executeSql(sql)
}


//18.日文章访问量
export const selectDataVisit = function () {
    let sql = "  select `date` publish_date,  SUM(`read`) daily_read_total from articles where isDelete = 0  group by `date`  order by `date` desc limit 7 ";
    return executeSql(sql)
}